//
//  LoveListViewController.m
//  Leisure
//
//  Created by lanou3g on 16/4/11.
//  Copyright © 2016年 wenze. All rights reserved.
//

#import "LoveListViewController.h"


@interface LoveListViewController ()<UITableViewDataSource,UITableViewDelegate>

@property (weak, nonatomic) IBOutlet UITableView *LoveListTableView;

@property (nonatomic,strong)NSMutableArray *loveListArray;

@end

@implementation LoveListViewController

- (NSMutableArray *)loveListArray{
    if (!_loveListArray) {
        _loveListArray = [[NSMutableArray alloc]init];
    }
    return _loveListArray;
}


- (void)viewDidLoad {
    [super viewDidLoad];
    
    // 添加退出按钮
    UIBarButtonItem *item = [[UIBarButtonItem alloc]initWithTitle:@"❎" style:(UIBarButtonItemStylePlain) target:self action:@selector(back:)];
    self.navigationItem.rightBarButtonItem = item;
    
}

- (void)back:(id)sender{
    DrawerViewController *menuController = (DrawerViewController*)((AppDelegate *)[[UIApplication sharedApplication] delegate]).rootTabBarViewController.drawerController;
    [menuController dismissViewControllerAnimated:YES completion:nil];
}

- (NSInteger )tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section{
    return self.loveListArray.count;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:@"cellId"];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:(UITableViewCellStyleSubtitle) reuseIdentifier:@"cellId"];
        
    }
    // 给cell赋值
    DianTaiInfoModel *model = [self.loveListArray objectAtIndex:indexPath.row];
    cell.textLabel.text = model.coverimg;
    cell.detailTextLabel.text = model.title;
    return cell;
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
    DianTaiInfoModel *model = [self.loveListArray objectAtIndex:indexPath.row];
    DianTaiInfoTableViewController *info = [[DianTaiInfoTableViewController alloc]init];
    info.radioid = model.tingid;
    
    [self.navigationController pushViewController:info animated:YES];
    
}

- (void)viewWillAppear:(BOOL)animated{
    // 获取数据
    DetailModleDB *db = [[DetailModleDB alloc]init];
    self.loveListArray = [[db selectModel] mutableCopy];
    [self.LoveListTableView reloadData];
    
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
